package com.my.study.algorithm.leetcode;

import java.util.*;

/**
 * 集合去重，
 * 
 * 
 * @author Carlos
 * @version 1.0.0
 * @date 2023/3/21 21:38
 */
public class ListNumberDis {

    public static void main(String[] args) {
        List<String> list = new ArrayList<>();
        list.add("123adcde");
        list.add("ad123cde");
        list.add("1234adcde");
        list.add("a1234dcde");
        list.add("adc1234de");

        System.out.println(isNumChar('a'));
        
        System.out.println(toDuplicate(list));
    }
    
    
    private static List<String> toDuplicate(List<String> list) {
        Map<String, String> map = new LinkedHashMap<>(2);
        for (String first : list) {
            String numStr = getNumStr(first);
            for (String second : list) {
                String numStr1 = getNumStr(second);
                if (numStr.equals(numStr1)) {
                    map.putIfAbsent(numStr, second);
                }
            }
        }
        
        return new ArrayList<>(map.values());
    }
    
    private static boolean isNumChar(char c) {
        return c >= 48 && c <= 57;
    }
    
    private static String getNumStr(String s) {
        char[] chars = s.toCharArray();
        StringBuilder sb = new StringBuilder();
        for (char c : chars) {
            if (isNumChar(c)) {
                sb.append(c);
            }
        }
        return sb.toString();
    }
    
}
